﻿using Cl.Model.DataBaseEntityDtos.Goods.BaseGoods;
using Cl.Model.DataBaseEntityDtos.Shops.BaseShop;
using Cl.Model.Results;
using Cl.Service.Service.Goods.BaseGoods;
using Cl.Service.Service.Shops.BaseShop;
using Cl.Utils;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Cl.WebApi.Areas.Customer.Shops
{
    /// <summary>
    /// 店铺管理
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.ClientGroup)]
    public class BaseShopController : BaseController
    {

        private readonly IBaseShopService BaseShopService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public BaseShopController(IBaseShopService baseShopService)
        {
            BaseShopService = baseShopService;
        }


        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<PageResultModel<BaseShopOutputDto>> Get([FromQuery] SearchBaseShopDto request)
        {
            return BaseShopService.Query(request);
        }

        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultInfoModel> Post([FromBody] BaseShopInputDto value)
        {
            var result = await BaseShopService.Save(value);
            return result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ResultInfoModel> Put([FromBody] BaseShopInputDto value)
        {
            return BaseShopService.Update(value);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ResultInfoModel> Delete([FromBody] List<int> ids)
        {
            return BaseShopService.Delete(ids);
        }

        /// <summary>
        /// 查找店铺的基础信息
        /// </summary>
        /// <param name="shopId"></param>
        /// <returns></returns>
        [HttpGet("FindShopData")]
        public async Task<BaseShopOutputDto?> FindShopData(int shopId)
        {
            return await BaseShopService.FindShopData(shopId);
        }

        /// <summary>
        /// 获取当前用户的店铺信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("FindUserShopData")]
        public async Task<BaseShopOutputDto?> FindUserShopData()
        {
            return await BaseShopService.FindUserShopData(GlobalUserManager.UserId);
        }

        /// <summary>
        /// 开启或关闭营业
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="enable"></param>
        /// <returns></returns>
        [HttpGet("OpenOrCloseShop")]
        public async Task<ResultInfoModel> OpenOrCloseShop(int shopId, bool enable)
        {
            return await BaseShopService.OpenOrCloseShop(shopId, enable);
        }

        /// <summary>
        /// 查询店铺首页信息
        /// </summary>
        /// <param name="shopId"></param>
        /// <param name="enable"></param>
        /// <returns></returns>
        [HttpGet("FindShopHomeInfo")]
        public async Task<ResultInfoModel> FindShopHomeInfo(int shopId)
        {
            return await BaseShopService.FindShopHomeInfo(shopId);
        }


        /// <summary>
        /// 申请店铺资质
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost("ApplyShopQualifications")]
        public async Task<ResultInfoModel> ApplyShopQualifications([FromBody] ShopQualificationInputDto obj)
        {
            return await BaseShopService.ApplyShopQualifications(obj);
        }


        /// <summary>
        /// 审批店铺资质
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost("AuditShopQualifications")]
        public async Task<ResultInfoModel> AuditShopQualifications([FromBody] ShopQualificationAuditDto obj)
        {
            if (obj == null) return GetResult.Error("参数不能为null");
            var result = await BaseShopService.AuditShopQualifications(obj);
            return result;
        }

        /// <summary>
        /// 上传店铺资质文件
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost("UploadShopQualificationFile")]
        public async Task<ResultInfoModel> UploadShopQualificationFile([FromForm] ShopQualificationInputDto obj)
        {
            return await BaseShopService.UploadShopQualificationFile(obj);
        }
    }
}
